package com.lc.afbx.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.lc.afbx.BaseApplication;
import com.lc.afbx.R;
import com.lc.afbx.conn.GetApiMineAddress;
import com.zcx.helper.util.UtilLog;

import java.util.List;

/**
 * Created by Administrator on 2016/6/1.
 */
public class AddressAdapter extends BaseAdapter {
    private List<GetApiMineAddress.Data> dataList;
    private LayoutInflater inflater;

    public AddressAdapter(Context context, List<GetApiMineAddress.Data> dataList) {
        inflater = LayoutInflater.from(context);
        this.dataList = dataList;
    }

    @Override
    public int getCount() {
        return dataList.size();
    }

    @Override
    public Object getItem(int position) {
        return dataList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder = null;
        if (convertView == null) {
            convertView = inflater.inflate(R.layout.item_address, null);
            BaseApplication.ScaleScreenHelper.loadView((ViewGroup) convertView);
            holder = new ViewHolder();

            holder.item_address_grey_line = (TextView) convertView.findViewById(R.id.item_address_grey_line);
            holder.name = (TextView) convertView.findViewById(R.id.txt_name);
            holder.phone = (TextView) convertView.findViewById(R.id.txt_phoneNum);
            holder.address = (TextView) convertView.findViewById(R.id.txt_address);
            holder.isDefault = (LinearLayout) convertView.findViewById(R.id.isDefault);

            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        if (dataList.get(position).is_first.equals("true")) {
//            UtilLog.e("地址里=====", "这好像没走啊" + dataList.get(position).is_first);
            holder.isDefault.setVisibility(View.VISIBLE);
        } else {
            holder.isDefault.setVisibility(View.GONE);
//            UtilLog.e("=====", "这好像没走啊" + dataList.get(position).is_first);

        }

        if (position == 0) {

            holder.item_address_grey_line.setVisibility(View.VISIBLE);

        }else {

            holder.item_address_grey_line.setVisibility(View.GONE);

        }


        holder.name.setText(dataList.get(position).rec_name);
        holder.phone.setText(dataList.get(position).phone);
        holder.address.setText(dataList.get(position).cur_address + dataList.get(position).road_address);
        return convertView;
    }

    class ViewHolder {
        TextView name, phone, address, item_address_grey_line;
        LinearLayout isDefault;

    }
}
